$(function () {
    let id = localStorage.getItem("roomId");
    findByRoomId(id);
});

//拿到数据
function findByRoomId(roomId) {
    $.ajax({
        url: '/back/room/findByRoomId',
        data: {roomId: roomId},
        type: 'get',
        dataType: 'json',
        // processData:  false ,
        // contentType:  false ,
        success: function (data) {
            showData(data.roomModel);
        }
    })
}

//把数据赋值给页面
function showData(data) {
    $("#roomId").val(data.roomId);
    $("#roomType option[text='"+data.roomType+"']").attr("selected", true);
    $("#roomPrice").val(data.roomPrice);
    $("#roomTitle").val(data.roomTitle);
    $("#roomPhoto").val(data.roomPhoto);
    $("#roomIntroduce").val(data.roomIntroduce);
}

//然后提交改后的数据到后台进行保存，成功后跳转到房间列表界面
function roomEdit() {
    let forData = new FormData();
    forData.append("roomId", $("#roomId").val());
    forData.append("roomType", $("#roomType").val());
    forData.append("roomPrice", $("#roomPrice").val());
    forData.append("roomTitle", $("#roomTitle").val());
    forData.append("roomPhoto", $("#roomPhoto")[0].files[0]);//文件取值
    forData.append("roomIntroduce", $("#roomIntroduce").val());
    $.ajax({
        url: '/back/room/roomEdit',
        data: forData,
        contentType: false,
        processData: false,
        type: 'post',
        dataType: 'json',
        success: function (data) {
            if (data.result === 1) {
                alert("提交成功");
                $("#right").load('../back/room/roomList.html');
            } else {
                alert("提交失败")
            }
        }
    })
}